#include <iostream>
#include <ctime>


/**
 * ##__VA_ARGS__ 表示如果__VA_ARGS__为空则将多余的逗号吞掉避免编译报错
 * 小于 当前日志等级(CUR_LOG_LEVEL) 的就不输出了
 */
#define INFO      1
#define DEBUG     2
#define ERROR     3
#define FATAL     4
#define CUR_LOG_LEVEL INFO
#define LOG(LOG_LEVEL, format, ...) do{\
    if(LOG_LEVEL < CUR_LOG_LEVEL) break;\
    time_t t = time(nullptr);\
    struct tm *local_tm = localtime(&t);\
    char time_str[32] = {0};\
    strftime(time_str, 31, "%Y-%m-%d %H:%M:%S", local_tm);\
    fprintf(stdout, " [%p %s %s:%d] " format "\n", \
       (void*)pthread_self(), time_str, __FILE__, __LINE__, ##__VA_ARGS__);\
    }while(0)


#define INFO_LOG(format, ...)      LOG(INFO, format, ##__VA_ARGS__)
#define DEBUG_LOG(format, ...)     LOG(DEBUG, format, ##__VA_ARGS__)
#define ERROR_LOG(format, ...)     LOG(ERROR, format, ##__VA_ARGS__)
#define FATAL_LOG(format, ...)     LOG(FATAL, format, ##__VA_ARGS__)